<?php session_start();
error_reporting(E_ALL);
if($_SESSION['loggin']==0||!isset($_SESSION['loggin']))
{
	die('You did not login, Please login first!');
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shopping cart</title>
</head>
<body>

<table border="1" cellpadding="10px" cellspacing="0">
    <tr>
    <th>Cart ID</th>
    <th>Product</th>
    <th>Price</th>
    <th>Quantity</th>
    <th>Time</th>                
    </tr>
<?php

		$connection = mysql_connect("localhost", "root", "");
		if ( !$connection ) {
			die('Could not connect to localhost.');	
		}
		$db = mysql_select_db("test", $connection);
		if ( !$db) {
			die ('Could not find database test.');	
		}
		
		echo $_SESSION['username'];
		
		if(isset($_REQUEST['submit']))
		{
			$dl = "DELETE FROM carts WHERE id='".$_POST['dlt']."'";
			mysql_query($dl,$connection)or die(mysql_error());  
			?>
            <br>
            <?php
			echo $dl;
		}
		
		//personal carts
		$cart = "select * from carts where member_name = '".$_SESSION['username']."'";
		
		$result = mysql_query($cart,$connection);
		
		//loop through all table rows
		while ($row = mysql_fetch_array($result)) {
			echo "<tr>";
			echo "<td>" . $row['id'] . "</td>";
			echo "<td>" . $row['p_name'] . "</td>";
			echo "<td>" . $row['p_price'] . "</td>";
			echo "<td>" . $row['quantity'] . "</td>";
			echo "<td>" . $row['date'] . "</td>";			
			echo "</tr>";										
		}
		mysql_close($connection);		
?>
</table>
<p>
</p>
<p>
<form action="bill.php" method="post">
	<table border="1"  cellpadding="10px" cellspacing="0">
    <tr>
    <th>Please Enter the Cart_ID to pay:</th>
    <td>
    <input type="text" name="pay" size="9" /> 
    </td>
    <td><input type="submit" name="submit" value="Pay" />
    </td>
    </tr>
</table>
</form>
<form action="shoppingcart.php" method="post">
<table border="1"  cellpadding="10px" cellspacing="0">
    <tr>
    <th>Please Enter the deleted Cart_ID:</th>
    <td>
    <input type="text" name="dlt" size="9" /> 
    </td>
    <td><input type="submit" name="submit" value="Delete" />
    </td>
    </tr>
</table>
</form>
</p>
</body>
</html>